import { modal } from 'vue-strap'
import { getBuyTypeList, addBuyType, showMsg } from '../../../../../vuex/action.js'

export default {
  data() {
    return {
      showAddBuyTypeModal: false,
      buytype: {
        title: '', //名称
        days: '', //天数
        price: '', //原始价
        actualPrice: '', //折后价
        amountType: 1 //0-人民币 1-港币 2-美元
      }
    }
  },
  props: {
    betaId: {
      type: Number,
      default: 0
    },
    betaName: {
      type: String,
      default: ''
    }
  },
  methods: {
    addPay() {
      this.buytypeList.push(1)
    },
    deletePay(index) {
      this.buytypeList.splice(index, 1)
    },
    trim(inStr) {
      return inStr.replace(/(^ +)|( +$)/g, '')
    },
    checkValid() {
      if (this.buytype.title.length === 0) {
        return '请输入套餐名称'
      } else if (this.buytype.days.length === 0) {
        return '请输入天数'
      } else if (this.buytype.price.length === 0) {
        return '请输入原始价'
      } else if (this.buytype.actualPrice.length === 0) {
        return '请输入折后价'
      }
    },
    evtAddBuyType() {
      let validMsg = this.checkValid()
      if (validMsg) {
        return this.xShowMsg({
          type: 'danger',
          content: validMsg
        })
      }

      this.xAddBuyType(this.buytype)
        .then((res) => {
          this.showAddBuyTypeModal = false
          this.$dispatch('on_refresh_list')
        })
    }
  },
  components: {
    modal: modal
  },
  vuex: {
    actions: {
      xShowMsg: showMsg,
      xAddBuyType: addBuyType,
      xGetBuyTypeList: getBuyTypeList
    }
  },
  ready() {
    // this.getBuyTypeList()
  }
}
